package ru.voronoy.thefifteen.gameplay;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;

public class TimerPrinter implements ActionListener {
	private JLabel label;
	private long startTime;
	private SimpleDateFormat df;
	private Date d;

	public TimerPrinter(JLabel label) {
		this.startTime = System.currentTimeMillis();
		this.d = new Date(System.currentTimeMillis());
		df = new SimpleDateFormat("HH:mm:ss");
		this.label = label;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (Game.getInstance().isStarted()) {
			d.setTime(System.currentTimeMillis() - startTime
					- CORRECTION_FACTOR);
			this.label.setText(df.format(d));
		}
	}

	private static final int CORRECTION_FACTOR = 18000000;
}
